<?php

namespace App\Http\Controllers\Admin;

use App\Model\Facades\AdminMenus;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Route;

class CommonCtrl extends Controller
{

    protected $roles = null;

    /**定义视图路径
     * 二位置数组viewRoot => 视图根目录
     *           viewDocumentRoot => 视图管理目录
     * CommonCrtl constructor.
     */
    public function __construct()
    {
        $args_arr = func_get_args();

        if (!empty($args_arr))
            $args_arr = $args_arr[0];


        if (empty($args_arr['viewRoot'])) {
            $this->viewRootPath = 'admin.';
        } else {
            $this->viewRootPath = $args_arr['viewRoot'] . '.';
        }

        if (empty($args_arr['viewDocumentRoot'])) {
            $bits = explode('\\', get_class($this));
            $this->viewDocument = end($bits) . '.';
        } else {
            $this->viewDocument = $args_arr['viewDocumentRoot'] . '.';
        }

        $this->viewRootPath .= $this->viewDocument;
    }



    protected function responseView($viewName, $data = [])
    {
        return response()->view($this->viewRootPath . $viewName, $data);
    }
}
